#include "Collision.h"
#include <graphics/mesh_instance.h>
#include <graphics/mesh.h>

//-- A collision helper file used throughout the project
namespace CollisionDetection
{
	//-- a method to perform AABB on the given 2 mesh instances
	bool AABB(abfw::MeshInstance A, abfw::MeshInstance B)
	{
		//-- check either mesh isn't equal to NULL
		if (A.mesh() == NULL || B.mesh() == NULL)
			return false;

		//-- Create and transform the AABBs
		abfw::Aabb BoxA = A.mesh()->aabb().Transform(A.transform());
		abfw::Aabb BoxB = B.mesh()->aabb().Transform(B.transform());
		
		//-- Return the result of the collision check
		return(BoxA.max_vtx().x > BoxB.min_vtx().x && 
			   BoxA.min_vtx().x < BoxB.max_vtx().x &&
			   BoxA.max_vtx().y > BoxB.min_vtx().y &&
			   BoxA.min_vtx().y < BoxB.max_vtx().y &&
			   BoxA.max_vtx().z > BoxB.min_vtx().z &&
			   BoxA.min_vtx().z < BoxB.max_vtx().z);
	}

}